package com.mspbots.rule.queue.producer;

import com.mspbots.cw.request.MessagesDTO;
import com.mspbots.dto.enums.Configuration;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import static com.mspbots.rule.config.RuleConfiguration.REDIS_KEY_PREFIX_SYSTEM;
import static com.mspbots.rule.config.RuleConfiguration.REDIS_KEY_PREFIX_TENANT;


/**
 * @ClassName com.mspbots.rule.queue.producer.MessageProducer
 * @Description TODO
 * @Author Jun
 * @Date 2019/8/28 15:53
 * @Version 1.0
 **/
@Service
public class MessageProducer {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private RabbitMessagingTemplate messagingTemplate;

    public void produce(MessagesDTO messagesDTO) {
        String systemSwitch = stringRedisTemplate.opsForValue().get(REDIS_KEY_PREFIX_SYSTEM + Configuration.MESSAGES_SWITCH.getKeyword());
        String tenantSwitch = stringRedisTemplate.opsForValue().get(REDIS_KEY_PREFIX_TENANT + messagesDTO.getTenantId() + ":" + Configuration.MESSAGES_SWITCH.getKeyword());
        if (!"off".equalsIgnoreCase(systemSwitch) && !"off".equalsIgnoreCase(tenantSwitch)) {
//            this.messagingTemplate.convertAndSend("msp.rule.ai", "queue.send", messagesDTO);
//            this.messagingTemplate.convertAndSend("msp.rule.ai", "queue.sendForward", messagesDTO);
        }
    }

}
